class Solution {
public:
    vector<int> preorder(Node* root) {
        vector<int> ans;
        if(root == NULL) return ans;
        ans.emplace_back(root->val);
        for(auto& c:root->children){
            auto temp = preorder(c);
            ans.insert(ans.end(),temp.begin(),temp.end());
        }
        return ans;
    }
};
